﻿using System.Collections.Generic;

namespace Raven
{
    public class FzAND : FuzzyTerm
    {
        private List<FuzzyTerm> _terms = new List<FuzzyTerm>();

        public FzAND(FzAND fa)
        {
            foreach (var curTerm in fa._terms)
            {
                _terms.Add(curTerm.Clone());
            }
        }

        public FzAND(FuzzyTerm op1)
        {
            _terms.Add(op1.Clone());
        }

        public FzAND(FuzzyTerm op1, FuzzyTerm op2)
        {
            _terms.Add(op1.Clone());
            _terms.Add(op2.Clone());
        }

        public FzAND(FuzzyTerm op1, FuzzyTerm op2, FuzzyTerm op3)
        {
            _terms.Add(op1.Clone());
            _terms.Add(op2.Clone());
            _terms.Add(op3.Clone());
        }

        public FzAND(FuzzyTerm op1, FuzzyTerm op2, FuzzyTerm op3, FuzzyTerm op4)
        {
            _terms.Add(op1.Clone());
            _terms.Add(op2.Clone());
            _terms.Add(op3.Clone());
            _terms.Add(op4.Clone());
        }

        public FuzzyTerm Clone()
        {
            return new FzAND(this);
        }

        public Fix GetDOM()
        {
            Fix smallest = Fix.MaxValue;
            foreach (var curTerm in _terms)
            {
                if (curTerm.GetDOM() < smallest)
                {
                    smallest = curTerm.GetDOM();
                }
            }

            return smallest;
        }

        public void ClearDOM()
        {
            foreach (var curTerm in _terms)
            {
                curTerm.ClearDOM();
            }
        }

        public void ORwithDOM(Fix val)
        {
            foreach (var curTerm in _terms)
            {
                curTerm.ORwithDOM(val);
            }
        }
    }

    public class FzOR : FuzzyTerm
    {
        private List<FuzzyTerm> _terms = new List<FuzzyTerm>();

        public FzOR(FzOR fa)
        {
            foreach (var curTerm in fa._terms)
            {
                _terms.Add(curTerm.Clone());
            }
        }

        public FzOR(FuzzyTerm op1)
        {
            _terms.Add(op1.Clone());
        }

        public FzOR(FuzzyTerm op1, FuzzyTerm op2)
        {
            _terms.Add(op1.Clone());
            _terms.Add(op2.Clone());
        }

        public FzOR(FuzzyTerm op1, FuzzyTerm op2, FuzzyTerm op3)
        {
            _terms.Add(op1.Clone());
            _terms.Add(op2.Clone());
            _terms.Add(op3.Clone());
        }

        public FzOR(FuzzyTerm op1, FuzzyTerm op2, FuzzyTerm op3, FuzzyTerm op4)
        {
            _terms.Add(op1.Clone());
            _terms.Add(op2.Clone());
            _terms.Add(op3.Clone());
            _terms.Add(op4.Clone());
        }

        public FuzzyTerm Clone()
        {
            return new FzOR(this);
        }

        public Fix GetDOM()
        {
            Fix largest = Fix.MinValue;
            foreach (var curTerm in _terms)
            {
                if (curTerm.GetDOM() > largest)
                {
                    largest = curTerm.GetDOM();
                }
            }

            return largest;
        }

        public void ClearDOM()
        {
            Utility.Assert(false, "<FzOR::ClearDOM>: invalid context");
        }

        public void ORwithDOM(Fix val)
        {
            Utility.Assert(false, "<FzOR::ORwithDOM>: invalid context");
        }
    }
}